var MGVoice = require('../FrameWork/Manager/MGVoice');
var EumPkGroup = require('./Enum/EumPkGroup');
var _ = require('./../FrameWork/we_underscore');
/***pk音效 */
var PkSound = module.exports = {};

PkSound.bgMusic = function() {
    var _musicPath = 'Pk/bg_music';
    MGVoice.playMusic(_musicPath);
};

PkSound.choiceCard = function() {
    MGVoice.playSoundByPath('deal');
};

PkSound.sendCard = function() {
    // var _soundPath = 'Pk/Other/sendCard';
    // MGVoice.playSoundByPath(_soundPath);
};

PkSound.playMoneyAnim = function() {
    var _soundPath = 'Pk/playMoney';
    MGVoice.playSoundByPath(_soundPath);
};

/***加倍声音 */
PkSound.double = function(_double, _sex) {
    var soundName = 'score_double'
    if (0 == _double) {
        soundName = 'score_double_none'
    }
    var _soundPath = this._getPkGroupTypeBasePath(_sex, soundName);
    MGVoice.playSoundByPath(_soundPath);
};

PkSound.callScore = function(_score, _sex) {
    var _soundPath = this._getPkGroupTypeBasePath(_sex, 'score_' + _score);
    MGVoice.playSoundByPath(_soundPath);
};

PkSound.randNoOut = function(_sex) {
    var randNum = _.random(0, 3);
    var _soundPath = this._getPkGroupTypeBasePath(_sex, 'pass_' + randNum);
    MGVoice.playSoundByPath(_soundPath);
};

/***_info:{
 *      type:1,//类型单，对，三带一，三带二，炸弹，王炸
 *      cardsInfo:[{id:1,type:1,value:1}]
 *      isFristOutCard:true//是否可随机播放要得起音效 
 *      sex:1,//性别
 * } */
PkSound.outCard = function(_info) {

    var _type = _info.type;
    var _sex = _info.sex;
    if (null == _info.isFristOutCard || false == _info.isFristOutCard) {
        if (EumPkGroup.BOMB != _type && EumPkGroup.BOMBKING != _type) {
            if (_.random(0, 5) > 4) {
                var randNum = _.random(0, 2);
                var _soundPath = this._getPkGroupTypeBasePath(_sex, 'kill_' + randNum);
                MGVoice.playSoundByPath(_soundPath);
                return;
            }
        }
    }
    var cardsInfo = _info.cardsInfo;
    if (EumPkGroup.ONE == _type) {
        this.outCardByCardInfo(cardsInfo[0], _sex);
    } else if (EumPkGroup.PAIRS == _type) {
        this.outPairs(cardsInfo, _sex);
    } else if (EumPkGroup.THREE == _type) {
        this.outThree(cardsInfo, _sex);
    } else if (EumPkGroup.EVENPAIRS == _type) {
        this.outEvenPairs(cardsInfo, _sex);
    } else if (EumPkGroup.THREE == _type) {
        this.outThree(cardsInfo, _sex);
    } else if (EumPkGroup.THREEONE == _type) {
        this.outThreeOne(cardsInfo, _sex);
    } else if (EumPkGroup.THREETWO == _type) {
        this.outThreeTwo(cardsInfo, _sex);
    } else if (EumPkGroup.THREEPAIRS == _type) {
        this.outThreePairs(cardsInfo, _sex);
    } else if (EumPkGroup.STRAIGHT == _type) {
        this.outStraight(cardsInfo, _sex);
    } else if (EumPkGroup.AIRCRAFT == _type) {
        this.outAircraft(cardsInfo, _sex);
    } else if (EumPkGroup.FOURONE == _type) {
        this.outFourOne(cardsInfo, _sex);
    } else if (EumPkGroup.FOURTWO == _type) {
        this.outFourTwo(cardsInfo, _sex);
    } else if (EumPkGroup.FOURTHREE == _type) {
        this.outFourThree(cardsInfo, _sex);
    } else if (EumPkGroup.FOURTWOPAIRS == _type) {
        this.outFourTwoPairs(cardsInfo, _sex);
    } else if (EumPkGroup.BOMB == _type) {
        this.outBomb(cardsInfo, _sex);
    } else if (EumPkGroup.BOMBKING == _type) {
        this.outBombKing(cardsInfo, _sex);
    }
};

/***通过卡牌id播放出牌音效 */
PkSound.outCardById = function(_cardId, _sex) {
    var cardInfo = PlanApi.PlanPkConfig.findById(_cardId);
    this.outCardByCardInfo(cardInfo, _sex);
};

/***对子
 * _cardInfo:{id:1,type:1,value:1} 
 */
PkSound.outCardByCardInfo = function(_cardInfo, _sex) {
    var value = _cardInfo.value;
    _sex = null == _sex ? 1 : _sex;
    var _sexPath = _sex == 1 ? 'Boy' : 'Girl';
    var _soundPath = 'Pk/Card/' + _sexPath + '/s_' + value;
    MGVoice.playSoundByPath(_soundPath);
};
/***对子
 * _cardsInfos:[{id:1,type:1,value:1}]
 */
PkSound.outPairs = function(_cardsInfos, _sex) {
    var size = _.size(_cardsInfos);
    if (2 == size) {
        var _soundPath = this._getPkCardBasePath(_cardsInfos, _sex, 'd_');
        MGVoice.playSoundByPath(_soundPath);
    }
};
/***连对
 * _cardsInfos:[{id:1,type:1,value:1}] EVENPAIRS
 */
PkSound.outEvenPairs = function(_cardsInfos, _sex) {
    var size = _.size(_cardsInfos);
    if (size >= 4) {
        var _soundPath = this._getPkGroupTypeBasePath(_sex, 'dd');
        MGVoice.playSoundByPath(_soundPath);
    }
};
/***三张牌
 * _cardsInfos:[{id:1,type:1,value:1}]
 */
PkSound.outThree = function(_cardsInfos, _sex) {
    var size = _.size(_cardsInfos);
    if (3 == size) {
        var _soundPath = this._getPkCardBasePath(_cardsInfos, _sex, 't_');
        MGVoice.playSoundByPath(_soundPath);
    }
};
/***三带一
 * _cardsInfos:[{id:1,type:1,value:1}]
 */
PkSound.outThreeOne = function(_cardsInfos, _sex) {
    var size = _.size(_cardsInfos);
    if (4 == size) {
        var _soundPath = this._getPkGroupTypeBasePath(_sex, 'tt_1');
        MGVoice.playSoundByPath(_soundPath);
    }
};
/***三带二
 * _cardsInfos:[{id:1,type:1,value:1}]
 */
PkSound.outThreeTwo = function(_cardsInfos, _sex) {
    var size = _.size(_cardsInfos);
    if (5 == size) {
        var _soundPath = this._getPkGroupTypeBasePath(_sex, 'tt_2');
        MGVoice.playSoundByPath(_soundPath);
    }
};
/***三带对子
 * _cardsInfos:[{id:1,type:1,value:1}]
 */
PkSound.outThreePairs = function(_cardsInfos, _sex) {
    var size = _.size(_cardsInfos);
    if (5 == size) {
        var _soundPath = this._getPkGroupTypeBasePath(_sex, 'tt_3');
        MGVoice.playSoundByPath(_soundPath);
    }
};
/***飞机 
 * _cardsInfos:[{id:1,type:1,value:1}]
 */
PkSound.outAircraft = function(_cardsInfos, _sex) {
    var size = _.size(_cardsInfos);
    if (size >= 6) {
        var _soundPath = this._getPkGroupTypeBasePath(_sex, 'ttt');
        MGVoice.playSoundByPath(_soundPath);
    }
};
/***顺子 
 * _cardsInfos:[{id:1,type:1,value:1}]
 */
PkSound.outStraight = function(_cardsInfos, _sex) {
    var size = _.size(_cardsInfos);
    if (size >= 5) {
        var _soundPath = this._getPkGroupTypeBasePath(_sex, 'ss');
        MGVoice.playSoundByPath(_soundPath);
    }
};

PkSound.outStraightAnim = function() {
    MGVoice.playSoundByPath('Pk/Other/shunZi');
};

/***四带一
 * _cardsInfos:[{id:1,type:1,value:1}]
 */
PkSound.outFourOne = function(_cardsInfos, _sex) {
    var size = _.size(_cardsInfos);
    if (5 == size) {
        var _soundPath = this._getPkGroupTypeBasePath(_sex, 'f_1');
        MGVoice.playSoundByPath(_soundPath);
    }
};
/***四带二
 * _cardsInfos:[{id:1,type:1,value:1}]
 */
PkSound.outFourTwo = function(_cardsInfos, _sex) {
    var size = _.size(_cardsInfos);
    if (6 == size) {
        var _soundPath = this._getPkGroupTypeBasePath(_sex, 'f_2');
        MGVoice.playSoundByPath(_soundPath);
    }
};
/***四带三 
 * _cardsInfos:[{id:1,type:1,value:1}]
 */
PkSound.outFourThree = function(_cardsInfos, _sex) {
    var size = _.size(_cardsInfos);
    if (7 == size) {
        var _soundPath = this._getPkGroupTypeBasePath(_sex, 'f_3');
        MGVoice.playSoundByPath(_soundPath);
    }
};

/***四带二对 
 * _cardsInfos:[{id:1,type:1,value:1}]
 */
PkSound.outFourTwoPairs = function(_cardsInfos, _sex) {
    var size = _.size(_cardsInfos);
    if (8 == size) {
        var _soundPath = this._getPkGroupTypeBasePath(_sex, 'f_4');
        MGVoice.playSoundByPath(_soundPath);
    }
};

/***炸弹 
 * _cardsInfos:[{id:1,type:1,value:1}]
 */
PkSound.outBomb = function(_cardsInfos, _sex) {
    var size = _.size(_cardsInfos);
    if (4 == size) {
        var _soundPath = this._getPkGroupTypeBasePath(_sex, 'bomb');
        MGVoice.playSoundByPath(_soundPath);
    }
};
PkSound.outBombAnim = function() {
    MGVoice.playSoundByPath('Pk/Other/bomb');
};
PkSound.outFeiJiAnim = function() {
    MGVoice.playSoundByPath('Pk/Other/plane');
};
PkSound.getOtherCardAnim = function() {
    MGVoice.playSoundByPath('Pk/Other/getOtherCard');
};

/***王炸   
 * _cardsInfos:[{id:1,type:1,value:1}]
 */
PkSound.outBombKing = function(_cardsInfos, _sex) {
    var size = _.size(_cardsInfos);
    if (2 == size) {
        var _soundPath = this._getPkGroupTypeBasePath(_sex, 'bomb_king');
        MGVoice.playSoundByPath(_soundPath);
    }
};

/***具体牌值 */
PkSound._getPkCardBasePath = function(_cardsInfos, _sex, _bfSound) {
    var _cardInfo = _cardsInfos[0];
    var _soundPath = this._getPkGroupTypeBasePath(_sex, _bfSound) + _cardInfo.value;
    return _soundPath;
};

/***无牌值 */
PkSound._getPkGroupTypeBasePath = function(_sex, _bfSound) {
    _sex = null == _sex ? 1 : _sex;
    var _sexPath = _sex == 1 ? 'Boy' : 'Girl';
    var _soundPath = 'Pk/Card/' + _sexPath + '/' + _bfSound;
    return _soundPath;
};